package com.mybatis.quartz.config;

import com.mybatis.quartz.job.Job1;
import org.quartz.*;
import org.quartz.impl.StdScheduler;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ScheduledThreadPoolExecutor;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail jobDetail1(){
        //关联job对象
        return JobBuilder.newJob(Job1.class).storeDurably().build();
    }

//    @Bean
//    public Trigger trigger1(){
//        //设置job1的一个执行规则
//        SimpleScheduleBuilder scheduleBuilder =SimpleScheduleBuilder.simpleSchedule()
//                .withIntervalInSeconds(2) //每十秒执行一次
//                .repeatForever(); //永久重复，一直执行下去
//        return TriggerBuilder.newTrigger()
//                .forJob(jobDetail1())
//                .withSchedule(scheduleBuilder)
//                .build();
//    }

    @Bean
    public Trigger trigger2(){
        //设置job1的一个执行规则
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/2 * * * * ? *");
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail1())
                .withSchedule(scheduleBuilder)
                .build();
    }


}

